package sudroid.android;

import android.content.Context;
import android.os.Handler;
import android.os.Looper;
import java.util.LinkedList;
import sudroid.LogUtils;
import sudroid.ThreadPoolRunnable;

public class ThreadPool extends ThreadGroup
{
  private static int threadPoolID;
  private boolean isAlive;
  private LinkedList<ThreadPoolRunnable> taskQueue;
  private int threadID;
  private Handler uiHandler;

  public ThreadPool(int paramInt, Context paramContext)
  {
    super(str);
    if (paramInt < 1)
      throw new IllegalArgumentException("numThreads must be greater than 1!");
    setDaemon(1);
    this.isAlive = 1;
    LinkedList localLinkedList = new LinkedList();
    this.taskQueue = localLinkedList;
    int j = 0;
    while (true)
    {
      if (j >= paramInt)
      {
        Looper localLooper = paramContext.getMainLooper();
        Handler localHandler = new Handler(localLooper);
        this.uiHandler = localHandler;
        return;
      }
      new PooledThread().start();
      j += 1;
    }
  }

  /** @deprecated */
  public void close()
  {
    monitorenter;
    try
    {
      if (this.isAlive)
      {
        this.isAlive = 0;
        this.taskQueue.clear();
        interrupt();
      }
      monitorexit;
      return;
    }
    finally
    {
      localObject = finally;
      monitorexit;
    }
    throw localObject;
  }

  /** @deprecated */
  protected ThreadPoolRunnable getTask()
    throws InterruptedException
  {
    monitorenter;
    try
    {
      while (true)
      {
        if (this.taskQueue.size() != 0);
        for (ThreadPoolRunnable localThreadPoolRunnable = (ThreadPoolRunnable)this.taskQueue.removeFirst(); ; localThreadPoolRunnable = null)
        {
          return localThreadPoolRunnable;
          if (this.isAlive)
            break;
        }
        wait();
      }
    }
    finally
    {
      monitorexit;
    }
    throw localObject;
  }

  public void join()
  {
    monitorenter;
    Object localObject1 = null;
    while (true)
    {
      Thread[] arrayOfThread;
      int j;
      try
      {
        this.isAlive = 0;
        notifyAll();
        monitorexit;
        arrayOfThread = new Thread[activeCount()];
        int i = enumerate(arrayOfThread);
        j = 0;
        if (j >= i)
          return;
      }
      finally
      {
        monitorexit;
      }
      try
      {
        arrayOfThread[j].join();
        j += 1;
      }
      catch (InterruptedException localInterruptedException)
      {
        while (true)
          LogUtils.e(localInterruptedException);
      }
    }
  }

  /** @deprecated */
  public void runTask(ThreadPoolRunnable paramThreadPoolRunnable)
  {
    monitorenter;
    try
    {
      if (!this.isAlive)
        throw new IllegalStateException();
    }
    finally
    {
      monitorexit;
    }
    if (paramThreadPoolRunnable != null)
    {
      boolean bool = this.taskQueue.add(paramThreadPoolRunnable);
      notify();
    }
    monitorexit;
  }

  class PooledThread extends Thread
  {
    public PooledThread()
    {
      super(str);
    }

    public void run()
    {
      while (true)
      {
        if (isInterrupted())
          label7: return;
        try
        {
          ThreadPoolRunnable localThreadPoolRunnable = ThreadPool.this.getTask();
          if (localThreadPoolRunnable == null)
            break label7;
          Handler localHandler1 = ThreadPool.this.uiHandler;
          ThreadPool.PooledThread.1 local1 = new ThreadPool.PooledThread.1(this, localThreadPoolRunnable);
          boolean bool1 = localHandler1.post(local1);
          Object localObject = localThreadPoolRunnable.run();
          Handler localHandler2 = ThreadPool.this.uiHandler;
          ThreadPool.PooledThread.2 local2 = new ThreadPool.PooledThread.2(this, localThreadPoolRunnable, localObject);
          boolean bool2 = localHandler2.post(local2);
        }
        catch (InterruptedException localInterruptedException)
        {
          LogUtils.e(localInterruptedException);
        }
      }
    }
  }
}

/* Location:           D:\Program Files\eclipse\apktool-r01-3\新浪微博\classes.dex.dex2jar.jar
 * Qualified Name:     sudroid.android.ThreadPool
 * JD-Core Version:    0.6.0
 */